package com.jiuwu.spring.eshop.db.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "tb_order")
@Data
@NoArgsConstructor
@DynamicInsert
public class OrderEt {

    @Id
    @Column(name = "OrderID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer orderID;

    @Column(name = "OrderNumber",nullable = false)
    private Integer orderNumber;

    @Column(name = "OrderName",nullable = false)
    private String orderName;

    @Column(name = "OrderTrueName",nullable = false)
    private String orderTrueName;

    @Column(name = "OrderAddress",nullable = false)
    private String orderAddress;

    @Column(name = "OrderPostcode")
    private String orderPostcode;

    @Column(name = "OrderTel",nullable = false)
    private String orderTel;

    @Column(name = "PayWay")
    private String payWay;

    @Column(name = "CarryWay")
    private String carryWay;


    @NumberFormat(style = NumberFormat.Style.PERCENT)
    @Column(name = "Rebate",nullable = false)
    private double rebate;


    @DateTimeFormat(pattern = "yyyy-mm-dd")
    @Column(name = "OrderDate",nullable = false)
    private Date orderDate;

    @Column(name = "IsEnforce")
    private Integer isEnforce;

    @Column(name = "Note")
    private String note;

    @Column(name = "IsComments")
    private Integer isComments;


    //@JoinTable中中间表无需建立实体，jpa自动创建
    @ManyToMany(targetEntity = Goods.class,cascade = CascadeType.PERSIST)
    @JoinTable(name = "tb_order_detail",
                joinColumns = {@JoinColumn(name = "OrderID",referencedColumnName = "OrderID")},
            inverseJoinColumns = {@JoinColumn(name = "GoodsID",referencedColumnName = "GoodsID")}    )
    private Set<Goods> goodsLst = new HashSet<>(); //默认需new()初始化，否则报空指针

}
